;
(function() {
  new Vue({
    el: '#report_bi',
    data: {
      quanxian: JSON.parse(localStorage.getItem('permissions')),
      arr: [],
      data: [],
      pagecount: ['10'],
      num: 0,
      pageTcount: [{name: '10', code: '10'}, {name: '15', code: '15'}, {name: '20', code: '20'}],
    },
    filters: {
      toZero: function (n) {
        return n < 10 ? '0' + n : '' + n
      },
      UTCdate: function (time) {
        return hlDateUtil.formatUTCDate(time, 'yyyy-MM-dd')
      },
      formatNum:function (num) {
        return hlNumberUtil.formatNum(num)
      },
      removal: function (arr) {
        function findInArr(item,arr) {
            for (var i = 0; i < arr.length; i++) {
                if (arr[i] == item) {
                    return true;
                }
            }
            return false;
        }
        var arr2 = [], arr3 = [];
        for (var i = 0; i < arr.length; i++) {
            if (!findInArr(arr[i],arr2)) {
              arr2.push(arr[i]);
            }
        }
        for (var i = 0; i < arr2.length; i++) {
          arr3.push(hlNumberUtil.formatNum(arr2[i]))
        }
        return arr3.join('/');
      }
    },
    methods: {
      pageFY: function (arr) {
        this.pagecount = [arr[0].code];
        var _this = this;
        setTimeout(function() {
          _this.pageIn()
        }, 200)
      },
      pageIn: function() {
        var _this = this;
        var pages = {
          "turnPage": function(n) {
            _this.getData(n, _this.arr);
          }
        }
        $("#page").initPage(1, 1, pages.turnPage);
      },
      getData: function(page, arr) {
        var _this = this;

        hlhttp.get({
          url: 'report/contract',
          data: {
            project_ids: _this.arr[0].toString() || _this.arr[1].toString(),
            page: page, //请求页
            page_count: _this.pagecount[0] //每页显示数量
          },
          success: function(res) {
            _this.num = res.totalCount;
            _this.data = res.contracts;
            $("#page").initPage(res.totalPage, page, function(n) {
              if (page == n) {
                return
              }
              _this.getData(n, _this.arr);
            });
          }
        })
      },
      excl: function () {
        if (!this.arr[0].length) {
          hl.toast('请选择项目')
          return
        }
        var _this = this;
        $.ajax({
          url: exclUrl+'resource/excel',
          type: 'get',
          headers: {
            token: Cookies.get("token"),
          },
          data: {
            project_ids: _this.arr[0].toString()
          },
          success: function (res) {

            var a = document.createElement('a');
            a.href = res.excel_url;
            $('body').append($(a))
            a.click();
            setTimeout(function() {
              $(a).remove()
            }, 100);
          }
        })
      }
    },
    mounted: function() {
      var _this = this;
      hlSelectUi(true)
      loginPrem.loginList()
      getProduct(function (data) {
        _this.arr = data;
        _this.pageIn(1, data)
      },function (data) {
        _this.arr = data;
        _this.pageIn(1, data)
      },function (data) {
        _this.arr = data;
        _this.pageIn(1, data)
      })
    }
  })
}())
